package com.woniuxy.reader.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.reader.entity.Book;
import com.woniuxy.reader.entity.Category;
import com.woniuxy.reader.service.BookService;
import com.woniuxy.reader.service.CategoryService;

import com.woniuxy.result.ResponseResult;
import io.swagger.annotations.Api;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zh_o
 * @since 2020-10-12
 */
@RestController
@RequestMapping("/category")
@Api(tags = "分类接口")
public class CategoryController {
    @Resource
    private CategoryService categoryService;
    @Resource BookService bookService;

    @GetMapping("{id}")
    public ResponseResult selectPageById(@PathVariable("id") Integer id){

        HashMap<Object, Object> map = new HashMap<>();
        //查询当前分类下的新书，按时间先后降序（新书）
        List<Book> newBookList = bookService.selectBooksByCreatetimeAndCategoryId(id);
        map.put("newBookList",newBookList);


        //查询当前分类下的书的点击量，按降序排序(人气排行)
        List<Book> clickBooksList = bookService.selectBooksByCategoryIdAndClickNum(id);
        map.put("clickBooksList",clickBooksList);



        //查询当前分类下的书的（本周强推）
        List<Book> thisWeekBooksList = bookService.selectBooksByCategoryIdAndCollection(id);
        map.put("thisWeekBooksList",thisWeekBooksList);

        //查询当前分类下的完结书籍
        List<Book> overBookList = bookService.selectBookByStauts(id);
        map.put("overBookList",overBookList);


        System.err.println(clickBooksList);
        return ResponseResult.success(map);
    }
}

